from sklearn.preprocessing import MinMaxScaler, StandardScaler
import pandas as pd

def minmax_demo():
    """
    特征预处理 - 归一化
    :return:
    """
    # 1.获取数据
    data = pd.read_csv("../resources/p01_machine_learning_sklearn/dating.txt", sep='\t')
    data = data.iloc[:,:3]
    print("data：\n", data)
    # 2.实例化一个转化器类
    transfer = MinMaxScaler()
    # transfer = MinMaxScaler(feature_range=[2, 3]) #带范围
    # 3.调用 fit_transform
    data_new = transfer.fit_transform(data)
    print("最小值最大值归一化处理的结果：\n", data_new)
    return None

def stand_demo():
    """
    特征预处理 - 标准化
    :return:
    """
    # 1.获取数据
    data = pd.read_csv("../resources/p01_machine_learning_sklearn/dating.txt", sep='\t')
    data = data.iloc[:,:3]
    print("data：\n", data)
    # 2.实例化一个转化器类
    transfer = StandardScaler()
    # 3.调用 fit_transform
    data_new = transfer.fit_transform(data)
    print("标准化处理的结果：\n", data_new)
    return None


if __name__ == "__main__":
    # 代码6：特征预处理 - 归一化
    minmax_demo()
    # 代码7：特征预处理 - 标准化
    stand_demo()